function Error = equilibrium_mapping(x,mu,sigmaS,sigmaT,N,lambda1,lambda2,q_team,q_sp,L_sp_end,L_team_end,F_end,L_sp,F_sp,L_team,F_team,aux_Teams,aux_Score,aux_sp)

iaux_Teams = aux_Teams+1;
K = @(x,sigma) x.^sigma;
EC_Z = @(z,sigma) z*sigma/(1+sigma); %E[c|c<z] (truncated expectation)
psi=1-lambda1-lambda2+2*lambda2*[0:1:N/2]'/N;
fun_p = @(q,V1,V2,sigma) K(max(q*(V1-V2),0),sigma);
fun_exp_max = @(p,q,V1,V2,sigma) p*(q*V1+(1-q)*V2+EC_Z(q*(V1-V2),sigma))+(1-p)*V2;

x=max(x,0);
F_sp_0=x(1);
F_sp_1=x(2);
F_team_0=x(3);
F_team_1=x(4);
L_sp_0=x(5);
L_team_1=x(6);

p_sub_f_sp_0 = fun_p(q_sp(aux_Score),L_sp(iaux_Teams,aux_Score+1),F_sp_0,sigmaS);
p_sub_f_sp_1 = fun_p(q_sp(aux_Score),L_sp(iaux_Teams,aux_Score+1),F_sp_1,sigmaS);
p_sub_f_team_0 = fun_p(q_team(aux_Score),L_team(iaux_Teams,aux_Score+1),F_team_0,sigmaS);
p_sub_f_team_1 = fun_p(q_team(aux_Score),L_team(iaux_Teams,aux_Score+1),F_team_1,sigmaS);
p_sub_l_sp_0 = fun_p(q_sp(aux_Score),L_sp(iaux_Teams,aux_Score+1),L_sp_0,sigmaS);
p_sub_l_team_1 = fun_p(q_team(aux_Score),L_team(iaux_Teams,aux_Score+1),L_team_1,sigmaS);
if aux_Teams<N/2
p_team_f_sp_0 = fun_p(1,F_sp(iaux_Teams+1,aux_Score),F_sp_0,sigmaT);
p_team_f_sp_1 = fun_p(1,F_sp(iaux_Teams+1,aux_Score),F_sp_1,sigmaT);
else
p_team_f_sp_0=0;
p_team_f_sp_1=0;
end

%%%%%%%%%F_sp
%aux_F_sp_own computes F_sp_own as a function of F^{sp}_{s,n,l} and
%p^sub
if aux_Teams<N/2
    aux_F_sp_own = @(p,F) fun_exp_max(p,q_sp(aux_Score),L_sp(iaux_Teams,aux_Score+1),F,sigmaS);
    F_sp_own_0 = aux_F_sp_own(p_sub_f_sp_0,F_sp_0);
    F_sp_own_1 = aux_F_sp_own(p_sub_f_sp_1,F_sp_1);
else
    F_sp_own_0=0;
    F_sp_own_1=0;
end
%aux_F_sp_forms_team computes F_sp_forms team as a function of
%F^{sp}_{s,n,l}, l, and p^team
if aux_Teams<N/2
    aux_F_sp_forms_team = @(p,F,l) fun_exp_max(p,1,F_team(iaux_Teams+1,aux_Score,1+l),F,sigmaT);
    F_sp_forms_team_0 = aux_F_sp_forms_team(p_team_f_sp_0,F_sp_0,0);
    F_sp_forms_team_1 = aux_F_sp_forms_team(p_team_f_sp_1,F_sp_1,1);
else
    F_sp_forms_team_0=0;
    F_sp_forms_team_1=0;
end
%computing F^{sp,rival team}
if aux_Teams>0
    aux_F_sp_rival_team = @(pl,pf,F,l) (l/iaux_Teams)*(pl*(q_team(aux_Score)*F_sp(iaux_Teams,aux_Score+1,1+1)+(1-q_team(aux_Score))*F)+(1-pl)*F)+((aux_Teams-l)/aux_Teams)*(pf*(q_team(aux_Score)*F_sp(iaux_Teams,aux_Score+1,1+1)+(1-q_team(aux_Score))*F)+(1-pf)*F);
    F_sp_rival_team_0 = aux_F_sp_rival_team(p_sub_l_team_1,p_sub_f_team_0,F_sp_0,0);
    F_sp_rival_team_1 = aux_F_sp_rival_team(p_sub_l_team_1,p_sub_f_team_1,F_sp_1,1);
else
    F_sp_rival_team_0=0;
    F_sp_rival_team_1=0;
end

%computing F^{sp,rival sp}
if aux_Teams<N/2
    aux_F_sp_rival_sp= @(pl,pf,F,l) ((1-l)/(aux_sp-1))*(pl*(q_sp(aux_Score)*F_sp(iaux_Teams,aux_Score+1,1+0)+(1-q_sp(aux_Score))*F)+(1-pl)*F)+((aux_sp-(1-l))/(aux_sp-1))*(pf*(q_sp(aux_Score)*F_sp(iaux_Teams,aux_Score+1,1+0)+(1-q_sp(aux_Score))*F)+(1-pf)*F);
    F_sp_rival_sp_0 = aux_F_sp_rival_sp(p_sub_l_sp_0,p_sub_f_sp_0,F_sp_0,0);
    F_sp_rival_sp_1 = aux_F_sp_rival_sp(p_sub_l_sp_0,p_sub_f_sp_1,F_sp_1,1);
else
    F_sp_rival_sp_0=0;
    F_sp_rival_sp_1=0;
end

%Computing F_sp_team forms
if aux_Teams<N/2
    aux_F_sp_team_forms = @(p,F,l) (1-p)*F + p*((1/(aux_sp-1))*F_team(iaux_Teams+1,aux_Score,1+l) + ((aux_sp-2)/(aux_sp-1))*F_sp(iaux_Teams+1,aux_Score,1+l));
    F_sp_team_forms_0 = aux_F_sp_team_forms(p_team_f_sp_0,F_sp_0,0);
    F_sp_team_forms_1 = aux_F_sp_team_forms(p_team_f_sp_1,F_sp_1,1);
else
    F_sp_team_forms_0=0;
    F_sp_team_forms_1=0;
end

eq_F_sp_0 = mu*F_end + (1-mu)*(psi(iaux_Teams)*F_sp_0 + (lambda1/N)*F_sp_own_0 + (lambda1*(2*aux_Teams)/N)*F_sp_rival_team_0 + lambda1*((aux_sp-1)/N)*F_sp_rival_sp_0 + lambda2*((aux_sp-1)/N)*F_sp_team_forms_0 + (lambda2/N)*F_sp_forms_team_0);
eq_F_sp_1 = mu*F_end + (1-mu)*(psi(iaux_Teams)*F_sp_1 + (lambda1/N)*F_sp_own_1 + (lambda1*(2*aux_Teams)/N)*F_sp_rival_team_1 + lambda1*((aux_sp-1)/N)*F_sp_rival_sp_1 + lambda2*((aux_sp-1)/N)*F_sp_team_forms_1 + (lambda2/N)*F_sp_forms_team_1);

%%%%%%%%%L_sp
L_sp_own_0 = fun_exp_max(p_sub_l_sp_0,q_sp(aux_Score),L_sp(iaux_Teams,aux_Score+1),L_sp_0,sigmaS);
L_sp_rival_team = p_sub_f_team_0*(q_team(aux_Score)*F_sp(iaux_Teams,aux_Score+1,1+1)+(1-q_team(aux_Score))*L_sp_0)+(1-p_sub_f_team_0)*L_sp_0;
L_sp_rival_sp = p_sub_f_sp_0*(q_sp(aux_Score)*F_sp(iaux_Teams,aux_Score+1,1+0)+(1-q_sp(aux_Score))*L_sp_0)+(1-p_sub_f_sp_0)*L_sp_0;
if aux_Teams<N/2
    L_sp_team_forms = p_team_f_sp_0*L_sp(iaux_Teams+1,aux_Score) + (1-p_team_f_sp_0)*L_sp_0;
else
    L_sp_team_forms=0;
end
eq_L_sp_0 = mu*L_sp_end + (1-mu)*((psi(iaux_Teams)+lambda2/N)*L_sp_0 + (lambda1/N)*L_sp_own_0 + (lambda1*(2*aux_Teams)/N)*L_sp_rival_team + lambda1*((aux_sp-1)/N)*L_sp_rival_sp + lambda2*((aux_sp-1)/N)*L_sp_team_forms);

%%%%%%%%%L_team
L_team_own_1 = fun_exp_max(p_sub_l_team_1,q_team(aux_Score),L_sp(iaux_Teams,aux_Score+1),L_team_1,sigmaS);
L_team_rival_team = p_sub_f_team_1*(q_team(aux_Score)*F_team(iaux_Teams,aux_Score+1,1+1)+(1-q_team(aux_Score))*L_team_1)+(1-p_sub_f_team_1)*L_team_1;
L_team_rival_sp = p_sub_f_sp_1*(q_sp(aux_Score)*F_team(iaux_Teams,aux_Score+1,1+0)+(1-q_sp(aux_Score))*L_team_1)+(1-p_sub_f_sp_1)*L_team_1;
if aux_Teams<N/2
    L_team_team_forms = p_team_f_sp_1*L_team(iaux_Teams+1,aux_Score) + (1-p_team_f_sp_1)*L_team_1;
else
    L_team_team_forms=0;
end
eq_L_team_1 = mu*L_team_end + (1-mu)*(psi(iaux_Teams)*L_team_1 + ((2*lambda1)/N)*L_team_own_1 + (lambda1*(2*(aux_Teams-1))/N)*L_team_rival_team + lambda1*(aux_sp/N)*L_team_rival_sp + lambda2*(aux_sp/N)*L_team_team_forms);

%%%%%%%%%%F_team
%fun_exp_max = @(p,q,V1,V2,sigma) p*(q*V1+(1-q)*V2+EC_Z(q*(V1-V2),sigma))+(1-p)*V2;
f_team_own_0 = fun_exp_max(p_sub_f_team_0,q_team(aux_Score),L_team(iaux_Teams,aux_Score+1),F_team_0,sigmaS);
f_team_own_1 = fun_exp_max(p_sub_f_team_1,q_team(aux_Score),L_team(iaux_Teams,aux_Score+1),F_team_1,sigmaS);

%computing F^{team,rival team}
if aux_Teams>1
    aux_F_team_rival_team = @(pl,pf,F,l) (l/(aux_Teams-1))*(pl*(q_team(aux_Score)*F_team(iaux_Teams,aux_Score+1,1+1)+(1-q_team(aux_Score))*F)+(1-pl)*F)+((aux_Teams-l)/(aux_Teams-1))*(pf*(q_team(aux_Score)*F_team(iaux_Teams,aux_Score+1,1+1)+(1-q_team(aux_Score))*F)+(1-pf)*F);
    F_team_rival_team_0 = aux_F_team_rival_team(p_sub_l_team_1,p_sub_f_team_0,F_team_0,0);
    F_team_rival_team_1 = aux_F_team_rival_team(p_sub_l_team_1,p_sub_f_team_1,F_team_1,1);
else
    F_team_rival_team_0=0;
    F_team_rival_team_1=0;
end

%computing F^{team,rival sp}
if aux_Teams<N/2
    aux_F_team_rival_sp= @(pl,pf,F,l) (l/(aux_sp))*(pl*(q_sp(aux_Score)*F_team(iaux_Teams,aux_Score+1,1+0)+(1-q_sp(aux_Score))*F)+(1-pl)*F)+((aux_sp-l)/(aux_sp))*(pf*(q_sp(aux_Score)*F_team(iaux_Teams,aux_Score+1,1+0)+(1-q_sp(aux_Score))*F)+(1-pf)*F);
    F_team_rival_sp_0 = aux_F_team_rival_sp(p_sub_l_sp_0,p_sub_f_sp_0,F_team_0,0);
    F_team_rival_sp_1 = aux_F_team_rival_sp(p_sub_l_sp_0,p_sub_f_sp_1,F_team_1,1);
else
    F_team_rival_sp_0=0;
    F_team_rival_sp_1=0;
end

if aux_Teams<N/2
    F_team_team_forms_0 = p_team_f_sp_0*F_team(iaux_Teams+1,aux_Score,1+0) + (1-p_team_f_sp_0)*F_team_0;
    F_team_team_forms_1 = p_team_f_sp_1*F_team(iaux_Teams+1,aux_Score,1+1) + (1-p_team_f_sp_1)*F_team_1;
else
    F_team_team_forms_0=0;
    F_team_team_forms_1=0;
end

eq_F_team_0 = mu*F_end + (1-mu)*(psi(iaux_Teams)*F_team_0 + ((2*lambda1)/N)*f_team_own_0 + (lambda1*(2*(aux_Teams-1))/N)*F_team_rival_team_0 + lambda1*((aux_sp)/N)*F_team_rival_sp_0 + lambda2*((aux_sp)/N)*F_team_team_forms_0);
eq_F_team_1 = mu*F_end + (1-mu)*(psi(iaux_Teams)*F_team_1 + ((2*lambda1)/N)*f_team_own_1 + (lambda1*(2*(aux_Teams-1))/N)*F_team_rival_team_1 + lambda1*((aux_sp)/N)*F_team_rival_sp_1 + lambda2*((aux_sp)/N)*F_team_team_forms_1);

%%%%%%%Checking convergence
Error = zeros(6,1);
Error(1) = F_sp_0 - eq_F_sp_0;
Error(2) = F_sp_1 - eq_F_sp_1;
Error(3) = F_team_0 - eq_F_team_0;
Error(4) = F_team_1 - eq_F_team_1;
Error(5) = L_sp_0 - eq_L_sp_0;
Error(6) = L_team_1 - eq_L_team_1;

%Error=Error'*Error;

% Error = zeros(6,1);
% Error(1) = eq_F_sp_0;
% Error(2) = eq_F_sp_1;
% Error(3) = eq_F_team_0;
% Error(4) = eq_F_team_1;
% Error(5) = eq_L_sp_0;
% Error(6) = eq_L_team_1;
